from selenium import webdriver
from time import sleep

driver = webdriver.Firefox()
url = 'https://www.baidu.com'
driver.get(url)

# 获取所有cookie
# cookies = driver.get_cookies()
# print(cookies)
# 获取指定的cookie
# print(driver.get_cookie('BD_UPN'))

sleep(3)
# 设置cookie
driver.add_cookie({
    'name': 'BDUSS',
    'value': 'hKfkxQb3N3WWdXWXJ2YTdGcVhGbUdUbGZGQXdyNHFKUE9ZZGY4WE5tZmlTY2htRVFBQUFBJCQAAAAAAAAAAAEAAACc4mBWx-fM7LfJ0-NkYXkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOK8oGbivKBmWn'
})
# 设置了cookie后，刷新页面
driver.refresh()



sleep(3)
driver.quit()